<?php
namespace app\api\controller;
use app\middleware\Auth;
use app\model\OrderLogisticsModel;
use app\model\OrdersModel;
use GuzzleHttp\Client;
use think\App;


class Wx extends Base {

    protected $middleware = [Auth::class];

    private $uid;

    private $req;

    private $token;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->req = request()->param();

        $this->token = request()->header("token");

        $this->uid = $this->isLogin();
    }



    /*
     * 获取快递公司列表
     *
     * */
    public function getLogistic(){

        if(!isset($this->req["waybill_id"]) || empty($this->req["waybill_id"])){
            return $this->fail("缺少参数：waybill_id");
        }

        if(!isset($this->req["delivery_id"]) || empty($this->req["delivery_id"])){
            return $this->fail("缺少参数：delivery_id");
        }

        try {
            $response = getLogistics($this->token, $this->req["waybill_id"], $this->req["delivery_id"]);
        }catch (\Exception $e){
            return $this->fail("网络异常：".$e->getMessage());
        }


        // 处理响应
        if ($response->getStatusCode() == 200) {
            $data = $response->getBody()->getContents();
            $data = json_decode($data, true);
            if(isset($data['errcode'])){
                return $this->fail("请求轨迹接口错误：错误码->".$data['errcode'].",错误信息->".$data['errmsg']);
            }

            return $this->succ($data);
        } else {
            return $this->fail("请求腾讯快递接口失败：". $response->getBody()->getContents());
        }
    }
}